<%@ page language="java" pageEncoding="utf-8"
	contentType="text/html; charset=utf-8"%>
<%@ include file="../include/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<%@ include file="../include/jsCss.jsp"%>
		<title>会员信息</title>
		<script>
	function deleteUser(id) {
		var dt = new Date();
		$.ajax( {
			type : "POST",
			url : "user!userDelete.html",
			data : "userDto.userId=" + id + "&date=" + dt,
			success : function(data) {
				if ($.trim(data) == 'success') {
					alert('删除成功');
					document.location.reload();
				}
			}
		});
	}
	
	function openUserAddRole(userId) {
		document.location.href = '${webUrl}/user/user!userAddRole.html?userDto.userId='+userId;
		//window.showModalDialog('${webUrl}/user/user!userAddRole.html?userDto.userId='+userId,'dialogHeight=310px;dialogWidth=360px,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
	}
	//审核通过
	function auditUser(status,type) {
		var userIds = "";
		var checkBool = true;
		$("input[name='userCheck']").each(function(i,item){
			 if (item.checked == true && checkBool == true) {
				 userIds += item.value + ",";
			 	if (item.alt != 1) { 
			 		checkBool = false;
			 		userIds = "";
			 		return;
			 	} 
			 	
			 }
		});
		
		if (!checkBool) {
			alert("只能审核餐厅商家会员!");
			return;
		}
		if (userIds == "") {
			alert("请选择要审核的会员!");
			return;
		}
		userIds = userIds.substring(0, userIds.length-1);
		var dt = new Date();
		$.ajax( {
			type : "POST",
			url : "user!updateUserStatus.html",
			data : "userIds="+userIds+"&status="+status+"&date=" + dt,
			success : function(data) {
				if ($.trim(data) == 0) {
					if (type == 1) { 
						alert('审核已通过!');
					}
					if (type == 2) {
						alert('审核不通过');
					}
					document.location.reload();
				}
			}
		}); 
	}
	
	//锁定
	function lockUser() {
		var userIds = ""; 
		$("input[name='userCheck']").each(function(i,item){
			 if (item.checked == true) {
				 userIds += item.value + ",";
				 alert(userIds);
			 	if (item.alt != 1) {  
			 		userIds = "";
			 		return;
			 	} 
			 }
		});
		 
		if (userIds == "") {
			alert("请选择要锁定的会员!");
			return;
		}
		userIds = userIds.substring(0, userIds.length-1);
		var dt = new Date();
		$.ajax( {
			type : "POST",
			url : "user!updateUserStatus.html",
			data : "userIds="+userIds+"&status=0&date=" + dt,
			success : function(data) {
				if ($.trim(data) == 0) { 
					alert('取消作废成功!'); 
					document.location.reload();
				}
			}
		}); 
	}
	//作废
	function cancelUser() {
	var userIds = ""; 
		$("input[name='userCheck']").each(function(i,item){
			 if (item.checked == true) {
				 userIds += item.value + ",";
			 	if (item.alt != 1) {  
			 		userIds = "";
			 		return;
			 	} 
			 	
			 }
		});
		
		 
		if (userIds == "") {
			alert("请选择要作废的会员!");
			return;
		}
		userIds = userIds.substring(0, userIds.length-1); 
		var dt = new Date();
		$.ajax( {
			type : "POST",
			url : "user!updateUserStatus.html",
			data : "userIds="+userIds+"&status=4&date=" + dt,
			success : function(data) {
				if ($.trim(data) == 0) { 
					alert('作废成功!'); 
					document.location.reload();
				}
			}
		}); 
	}
	//全选
	function checkedAll(t) { 
		$("input[name='userCheck']").each(function(i,item){
			 item.checked = t.checked;
		}); 
	}
</script>

	</head>

	<body>
		<form action="user!userList.html" method="post">
				<table border="1" width="140%">
					<tr>
						<th colspan="14">
							<h2>
								会员信息
							</h2>
						</th>
					</tr>
					<tr> 
						<td style="border:0px;">
							用户名：
						</td>
						<td style="border: 0px;">
							<input type="text" name="userName" />
						</td>
						<td style="border: 0px;">
							用户类型：
						</td>
						<td style="border: 0px;">															
							<s:select headerKey="" headerValue="请选择" name="userType" id="userType" list="#{'0':'前台会员','1':'餐厅商家','2':'后台人员'}" ></s:select>
							
						</td>
						<td style="border: 0px;">
							手机号码：
						</td>
						<td style="border: 0px;">
							<input type="text" name="userPhone" />
						</td>
						<td style="border: 0px;">
							<input type="submit" value="搜索" />
						</td>
						
						<td colspan="7"
							style="border: 0px; text-align: right; padding-right: 20px;">
							<a href="user!userAdd.html">添加后台会员</a> 
							<input type="button" value="审核通过" onclick="auditUser(0,1)"/>
							<input type="button" value="审核不通过" onclick="auditUser(2, 2)"/>
							<input type="button" value="作废" onclick="cancelUser(4)"/>
							 <input type="button" value="取消作废" onclick="lockUser(0)"/>
						</td>
					</tr>
					<tr>
						<td><input type="checkbox" onclick="checkedAll(this)"> </td>
						<td>
							序号
						</td>
						<td>
							用户名
						</td>
						<td>
							真实姓名
						</td>
						<td>
							用户性别
						</td>
						<td>
							身份证号码
						</td>
						<td>
							固定电话
						</td>
						<td>
							手机
						</td>
						<td>
							地址
						</td>
						<td>
							邮编
						</td>
						<td>
							邮箱
						</td>
						<td>
							用户类型
						</td>
						<td>
							状态
						</td>
						<td>
							操作
						</td>
					</tr>
					<s:iterator value="userList" status="status">
						<tr>
							<td><input type="checkbox" name="userCheck" value="${userId }" alt="${userType }"/></td>
							<td>
								<s:property value="#status.index+1"/> 
							</td>
							<td>
								${userName } 
							</td>
							<td>
								${realName }
							</td>
							<td>
								<s:if test="userSex == 0">男 </s:if>
								<s:if test="userSex == 1">女</s:if>
							</td>
							<td>
								${userIdNo }
							</td>
							<td>
								${userMobile } 
							</td>
							<td>
								${userPhone }
							</td>
							<td>
								${userAddress }
							</td>
							<td>
								${userZipCode }
							</td>
							<td>
								${userEmail }
							</td>
							<td>
								<s:if test="userType == 0">前台会员 </s:if>
								<s:if test="userType == 1">餐厅商家</s:if>
								<s:if test="userType == 2">后台管理员</s:if>
							</td>
							<td>
								<s:if test="status == 0">有效</s:if>
								<s:if test="status == 1">审核中</s:if>
								<s:if test="status == 2">审核不通过</s:if>
								<s:if test="status == 4">作废</s:if>
								<!--<s:if test="status == 0">取消作废</s:if>-->
							</td>
							<td>
								<a
									href="user!userUpdate.html?userId=${userId }">修改
								</a> 
								|
								<a href="javascript:deleteUser(${userId })">删除</a>
								|
								<a
									href="javascript:;" onclick="openUserAddRole(${userId})">绑定角色</a>
							</td>
						</tr>
					</s:iterator>
				</table>  
				<div>
					<jsp:include page="../include/page.jsp"></jsp:include> 
				</div>
		</form>
	</body>
</html>